package model;

import java.util.ArrayList;

/**
 *
 * @author Dustin
 */
public class Deck {

    private ArrayList<Card> cards = new ArrayList<Card>();

    public Deck() {
        reset();
        shuffle();
    }

    public int getSize() {
        return cards.size();
    }

    /**
     * Command to remove and return the first Card in this Deck
     * @return
     */
    public Card pop() {
        return cards.remove(0);
    }

    /**
     * Command to shuffle this Deck. While in a single loop, 
     * a random card will be switched with the card at the current index
     */
    public void shuffle() {
        for (int i = 0; i < cards.size(); i++) {
            Card temp = cards.get(i);
            int shuffledIndex = (int) (Math.random() * cards.size());
            Card shuffled = cards.get(shuffledIndex);
            cards.set(i, shuffled);
            cards.set(shuffledIndex, temp);
        }
    }

    /**
     * Comman to reset this Deck thus removing all left over cards and adding
     * the default cards in order.
     */
    public void reset() {
        cards.removeAll(cards);
        for (int suite = 0; suite < Card.SUITES; suite++) {
            for (int rank = 7; rank <= 14; rank++) {
                Card c = new Card(suite, rank);
                cards.add(c);
            }
        }
    }
}
